<template>
  <a-layout style="min-height: 100vh">
    <a-layout-sider v-model:collapsed="collapsed" collapsible>
      <div class="logo" style="text-align: center;">
        <img style="width: 80px;" src="@/assets/img/bj.webp"  />
        </div>

      <a-menu 
      @select="djtz"
       v-model:selectedKeys="selectedKeys" theme="dark" mode="inline">
       
        <div v-for="(sj,sy) in list">

        <a-sub-menu  :key="sj.menu_id" v-if="sj.children.length>0">
          <template #title>
            <span>
             <icon :icon="sj.icon"></icon>
             <!-- <span class="iconfont icon-uni-icons-gear"></span> -->
              <span>{{sj.name}}</span>
            </span>
          </template>
          <a-menu-item v-for="(sjj,sy) in sj.children" :key="sjj.menu_id"  :url="sjj.url">
           {{sjj.name}}
          </a-menu-item>
        
        </a-sub-menu>

 
                                                    <!-- url是自定义的 -->
        <a-menu-item :key="sj.menu_id+''" v-else :url="sj.url">
        <icon :icon="sj.icon"></icon>
          <span>
            {{sj.name}}
          </span>
        </a-menu-item>

       
      </div>
       

    
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0" >

        <div class="dsp">
          <div>
          欢迎
          </div>


          <div style="display:flex;">
            <div>
     {{nickname}}
        </div>
        <div class="tpp">
            <a-image 
    :width="60"
    :src="avatar"
  /> 
        </div>
  <div>
           <a-button @click="signOut">
            退出
           </a-button> 
          </div>     
           </div>
        
        </div>
      </a-layout-header>
      <a-layout-content style="margin: 0 16px">
        <a-breadcrumb style="margin: 16px 0">
          <a-breadcrumb-item>User</a-breadcrumb-item>
          <a-breadcrumb-item>Bill</a-breadcrumb-item>
        </a-breadcrumb>



        <div :style="{ padding: '24px', background: '#fff', minHeight: '360px' }">
          <!-- {{list}} -->
          <RouterView></RouterView>
        </div>



      </a-layout-content>
      <a-layout-footer style="text-align: center">
        Ant Design ©2018 Created by Ant UED
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>
<script setup lang="ts">

import { ref ,toRefs} from 'vue';
// import {fzgz} from '@/views/Index/index'
import {usesmenutore} from '@/stores/index'
import {useRouter,useRoute} from 'vue-router'
// import {removeRoute} from '@/stores/Menu/DynamicRouting'
import {removeRoute} from '@/stores/Menu/DynamicRouting/dynamicrouting'
import {usestore} from '@/stores/user/counter'
import {signout} from '@/api/logon/signOut'
import { message } from 'ant-design-vue';
const router = useRouter()
const route=useRoute()
console.log(route)
let dqly=route.meta.menu_id as string
let gbsj=usesmenutore()
console.log(gbsj)
let list=gbsj.list as any[]
console.log(list)
let ff=usestore()
let {nickname,avatar}=toRefs(ff.userInfo)
console.log(ff.token)
console.log(ff.userInfo)
// let router=useRoute()
// let {list} =fzgz()
// let {selectedKeys} =fzgz()
// let {djtz} = fzgz()
function djtz(e:any){
  console.log(e)
  router.push(e.item.url)
}
let selectedKeys = ref<string[]>([dqly])
  let collapsed = ref<boolean>(false)


  function signOut(){
    signout().then((res:any)=>{
      console.log(res)
      if(res.code==0){
     message.success(res.msg)
    localStorage.clear()
    gbsj.$reset()
    removeRoute()
    router.push('Logon')

      }
    })
    // localStorage.clear()
    // gbsj.$reset()
    // removeRoute()
    // router.push('Logon')
  }
// let children=list[0].children
//          let menu_id=children.length >0 ? children[0].menu_id:list[0].menu_id
//          selectedKeys.value=[menu_id]
// let list = ref([])
// function jkff(){
//     userInfo().then((res:any)=>{
//          console.log(res)
//          list.value=res.list
//     }).catch((err)=>{
//         console.log(err)
//     })
  
// }
// onMounted(()=>{
//     jkff()
   
// })

 
// let selectedKeys = ref<string[]>([])

</script>
<style>
#components-layout-demo-side .logo {
  height: 32px;
  margin: 16px;
  background: rgba(255, 255, 255, 0.3);
}

.site-layout .site-layout-background {
  background: #fff;
}
[data-theme='dark'] .site-layout .site-layout-background {
  background: #141414;
 
}
.dsp{
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
}
.tpp{
margin: 0 30px;
}
</style>
